package com.zzptc.zzsgz.bdsjws.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.UpdataVersionFragment;
import com.zzptc.zzsgz.bdsjws.vo.VersionInfo;

import butterknife.BindView;
import butterknife.OnClick;

public class UpdateActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_update;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

    }
    @OnClick(R.id.textView2)
    public void OnclickUpdate(View view){
        //startActivities(new Intent[]{new Intent(this, CheckUpdateActivity.class)});
        startActivityForResult(new Intent(this,CheckUpdateActivity.class),0);
    }
    public void showDialog(String msg){
        FragmentManager fm=getFragmentManager();
        UpdataVersionFragment u1=UpdataVersionFragment.getUpdataVersionFragment(msg);
        //终于让对话框出现了
        u1.show(fm,"");
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                Toast.makeText(this, "没网了。。。。", Toast.LENGTH_SHORT).show();
                showDialog("没网了。。。。");
                break;
            case 2:
                Toast.makeText(this, "有网络，比较慢", Toast.LENGTH_SHORT).show();
                showDialog("有网络，比较慢");
                break;
            case 3:
                VersionInfo versionInfo= (VersionInfo) data.getSerializableExtra("VresionInfo");
                //接收
                //Toast.makeText(this, "网络正常，可以下载", Toast.LENGTH_SHORT).show();
                //Toast.makeText(this, versionInfo.getApkurl()+"", Toast.LENGTH_SHORT).show();
                FragmentManager fm=getFragmentManager();
                UpdataVersionFragment u=UpdataVersionFragment.getUpdataVersionFragment(versionInfo);
                //终于让对话框出现了
                u.show(fm,"");
                break;
            case 4:
                Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
                showDialog("已经是最新版本");
                break;
        }
    }

}
